<template>
  <div class="app-container">
    <!-- 任务列表 -->
    <el-table v-loading="loading" :data="taskList">
      <!--      <el-table-column label="流程ID" align="center" prop="id"/>-->
      <el-table-column label="流程名称" align="center" prop="instanceName"/>
      <el-table-column label="任务节点名称" align="center" prop="name"/>
      <el-table-column label="任务状态" align="center" prop="status"/>
      <el-table-column label="办理人" align="center" prop="assignee"/>
      <el-table-column label="创建时间" align="center" prop="createdDate"/>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="examineAndApprove(scope.row)"
            v-hasPermi="['workflow:leave:edit']"
          >审批
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 审批对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="auto"
        class="demo-ruleForm"
        inline
        disabled
      >
        <el-form-item label="单据编号" prop="orderCode">
          <el-input
            v-model="form.saleBackRequestCode"
            placeholder="请输入"
            disabled
          />
        </el-form-item>
        <el-form-item label="单据日期" prop="createDate">
          <el-date-picker
            clearable
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择单据日期"
          />
        </el-form-item>
        <el-form-item label="客户" prop="cusName">
          <el-input
            v-model="form.cusName"
            placeholder="请输入"
            disabled
          />
        </el-form-item>
        <el-form-item label="金额" prop="total">
          <el-input :value="form.total" placeholder="" disabled/>
        </el-form-item>
      </el-form>
      <el-form
        :model="approval"
        ref="form"
        label-width="100px"
        class="demo-dynamic"
      >
        <el-form-item label="审批结果">
          <el-radio-group v-model="approval.approvalResult">
            <el-radio :label="1">同意</el-radio>
            <el-radio :label="2">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审批意见">
          <el-input
            type="textarea"
            v-model="approval.approvalOption"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listTask, handleApproval, reciveReqShow} from "@/api/activiti/task";
import request from "@/utils/request";

export default {
  name: "Leave",
  data() {
    return {
      id: "",
      definitionKey: "",
      businessKey: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 请假表格数据
      taskList: [],
      buyBackReq: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单是否禁用
      formDisabled: true,
      // 查询参数
      queryParams: {
        processDefinitionKey: "saleBackReq",
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        orderUser: {userName: ""},
        approvalUser: {userName: ""},
      },
      approval: {
        approvalResult: 2,
        approvalOption: "",
      },
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {

    /** 查询销售退货申请列表 */
    getList() {
      this.loading = true;
      listTask(this.queryParams).then((response) => {
        this.taskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      (this.definitionKey = ""),
        (this.businessKey = ""),
        (this.form = {
          orderUser: {userName: ""},
          approvalUser: {userName: ""},
        });
      this.resetForm("form");
    },
    /** 审批按钮操作 */
    examineAndApprove(row) {
      this.reset();
      this.definitionKey = row.definitionKey;
      this.businessKey = row.businessKey;
      this.id = row.id;
      request({
        url: '/activiti/approval/saleBackReqShow/' + this.id,
        method: 'get',
      }).then(res => {
        this.form = res.data;
      });
      this.open = true;
      this.title = "审批销售退货单";
    },
    /** 提交按钮 */
    submitForm() {
      this.approval.taskId = this.id;
      handleApproval(this.approval).then((response) => {
        this.$modal.msgSuccess("审批成功");
        this.open = false;
        this.getList();
      });
    },
    /**文档预览**/
    preView(filePath) {
      console.info(filePath);
      if (null == filePath || "" == filePath) {
        this.$alert("申请人没有上传哦", "消息提示", {
          confirmButtonText: "确定",
        });
      } else {
        // let originUrl = 'http://127.0.0.1:80/ruoyi-admin/';   //要预览文件的访问地址'
        window.open(filePath);
      }
      // const bb = originUrl  + aa;
      // window.open('http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(bb)));
    },
    /** 选择用户按钮操作 */
    handleSelectUser() {
      this.innerUserVisible = true;
      this.getUserList();
      this.getDeptTree();
    },
  },
};
</script>
